package org.lemon.cla.enums;

import com.baomidou.mybatisplus.annotation.IEnum;
import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonValue;
import org.lemon.cla.exception.BusinessException;

public enum ClubMemberStatusEnum implements IEnum<String> {
    APPLYING("申请中"),
    JOINED("已加入"),
    REJECTED("已拒绝");

    private final String description;

    ClubMemberStatusEnum(String description) {
        this.description = description;
    }

    @Override
    @JsonValue
    public String getValue() {
        return this.description;
    }

    public String getDescription() {
        return description;
    }

    @JsonCreator
    public static ClubMemberStatusEnum fromDescription(String description) {
        for (ClubMemberStatusEnum status : ClubMemberStatusEnum.values()) {
            if (status.getDescription().equals(description)) {
                return status;
            }
        }
        throw new BusinessException(HttpStatusEnum.UNSUPPORTED_TYPE.getCode(),"非法的枚举: "+description);
    }
}